package com.tuniu.agents.common.entity.itinerary.resource;

import com.tuniu.agents.common.entity.itinerary.Resource;
import com.tuniu.agents.common.entity.itinerary.enums.ResourceStatus;
import com.tuniu.agents.common.entity.itinerary.enums.ResourceType;

import java.math.BigDecimal;
import java.util.Objects;

public class FlightResource extends Resource {

    /**
     * airline company
     */
    private String airlineCompany;

    /**
     * departure city name
     */
    private String departureCityName;

    /**
     * arrival city name
     */
    private String arrivalCityName;

    /**
     * false one-way, true round
     */
    private boolean isRound;
    public FlightResource(){
    }
    public FlightResource(String airlineCompany, String departureCityName, String arrivalCityName, String departureDate, String markdown, BigDecimal price, ResourceStatus status) {
        super(ResourceType.FLIGHT, departureDate, null, markdown, price, status);
        this.airlineCompany = airlineCompany;
        this.departureCityName = departureCityName;
        this.arrivalCityName = arrivalCityName;
    }

    public FlightResource(String airlineCompany, String departureCityName, String arrivalCityName, String departureDate, Object data, String markdown, BigDecimal price, ResourceStatus status) {
        super(ResourceType.FLIGHT, departureDate, data, markdown, price, status);
        this.airlineCompany = airlineCompany;
        this.departureCityName = departureCityName;
        this.arrivalCityName = arrivalCityName;
    }

    @Override
    public boolean match(Resource resource) {
        if (this == resource) {
            return true;
        }
        if (!(resource instanceof FlightResource)) {
            return false;
        }

        FlightResource flightResource = (FlightResource) resource;
        return Objects.equals(getUseDate(), flightResource.getUseDate()) &&
               Objects.equals(departureCityName, flightResource.departureCityName) &&
               Objects.equals(arrivalCityName, flightResource.arrivalCityName);
    }

    @Override
    public String createTemplateName() {
        if (!isRound) {
            return "flight/flight-list-one.ftlh";
        } else {
            return "flight/flight-list-round.ftlh";
        }
    }

    public String getAirlineCompany() {
        return airlineCompany;
    }

    public void setAirlineCompany(String airlineCompany) {
        this.airlineCompany = airlineCompany;
    }

    public String getDepartureCityName() {
        return departureCityName;
    }

    public void setDepartureCityName(String departureCityName) {
        this.departureCityName = departureCityName;
    }

    public String getArrivalCityName() {
        return arrivalCityName;
    }

    public void setArrivalCityName(String arrivalCityName) {
        this.arrivalCityName = arrivalCityName;
    }
}
